 $('#moreunfold').click(function() {
     $('.main li:gt(3)').css('display', 'block');
     $("#pack_up").css('display', 'block');
     $('#moreunfold').css('display', 'none');
 })
 $('#pack_up').click(function() {
     $('.main li:gt(3)').css('display', 'none');
     $("#pack_up").css('display', 'none');
     $('#moreunfold').css('display', 'block');
 })

 var OrderId = sessionStorage.getItem("OrderId");
 var sdType = sessionStorage.getItem("OrderType");
 var IsPingJia = "0"; //评价
 var PeiSongId = "0";
 var peiSongStatus = "",
     peiSongStatus2 = "",
     peiSongStatusTime = "";
 var orderStatus = "1";
 var status1 = true,
     status2 = true,
     status3 = true,
     status3 = true,
     status4 = true,
     status5 = true,
     status6 = true,
     status7 = true;
 // order_num down_order_time buy_add receiver_add goods_type order_money order_distance desc
 //获取订单详情(买送取)
 $(".assess_button").css("display", "none");
 if (sdType === "0" || sdType === "1" || sdType === "2") {
     var orderDetail = function ajaxOrderDetail() {
         $.ajax({
             type: "get",
             url: currentUrl + "/interfaceDOC/firstProject/User.ashx?action=Get_OrderDetail",
             data: {
                 "OrderId": OrderId
             },
             dataType: "json",
             success: function(data) {
                 console.log(data)
                 if (data.msgcode == "1") {
                     orderStatus = data.data.Status;
                     //console.log(orderStatus);
                     // 初始化Dom
                     IsPingJia = data.data.IsPingJia;
                     if (IsPingJia == "0") {
                         $(".assess_button").html("评价");
                     } else {
                         $(".assess_button").html("再来一单");
                     }
                     $(".time_output").html(data.data.DownOrderTime);
                     $("#order_num span").html(data.data.OrderNum);
                     $("#down_order_time span").html(data.data.DownOrderTime);
                     $("#buy_add span").html(data.data.QIAddress);
                     $("#receiver_add span").html(data.data.ZhongAddress);
                     $("#receiver_tel span").html(data.data.ZhongTel);
                     $("#goods_type span").html(data.data.GoodsType);
                     $("#order_money span").html("￥" + data.data.Money);
                     $("#order_distance span").html(data.data.QuJuLi);
                     $("#desc span").html(data.data.Desc);
                     $("#peisong_name").html(data.data.Name);
                     $("#peisong_tel").html(data.data.Phone);
                     $("#call_peisong").click(function() {
                             window.location.href = "tel:" + data.data.Phone;
                         })
                         //闪电买取地址名称
                     if (sdType == "0") {
                         $("#buy_add .name").html("购买地址");
                         $("#receiver_add .name").html("取货地址");
                     } else if (sdType == "1" || sdType == "2") {
                         $("#buy_add .name").html("取货地址");
                         $("#receiver_add .name").html("收货地址");
                     }
                     $("#courier_header").css("background-image", "url(" + data.data.Image + ")");
                     //取消订单，返回首页;
                     if (orderStatus === 8) {
                         window.location.href = "../index.html";
                     }
                     (orderStatus == 10 ? orderStatus = 3 : orderStatus);
                     for (var i = 0; i <= orderStatus; i++) {
                         switch (i) {
                             case 1:
                                 if (status1 == true) {
                                     $(".order_state").html("等待取货");
                                     peiSongStatus = "闪电侠接单成功";
                                     peiSongStatus2 = "等待闪电侠购买";
                                     peiSongStatusTime = data.data.QingDate;
                                     addStatus();
                                     status1 = false;
                                 }
                                 break;
                             case 2:
                                 if (status2 == true) {
                                     peiSongStatus = "跑男正在前往购买地,请耐心等待";
                                     peiSongStatus2 = "等待闪电侠购买";
                                     peiSongStatusTime = data.data.QuChuFaDate;
                                     addStatus();
                                     status2 = false;
                                 }
                                 break;
                             case 3:
                                 if (status3 == true) {
                                     peiSongStatus = "闪电侠已到达购买地点";
                                     peiSongStatus2 = "等待闪电侠购买";
                                     peiSongStatusTime = data.data.DaoDaDate;
                                     addStatus();
                                     status3 = false;
                                 }
                                 break;
                             case 4:
                                 if (status4 == true) {
                                     $(".order_state").html("已完成");
                                     $(".time_output").css("display", "none");
                                     $(".time_output").html(data.data.DownOrderTime);
                                     $("#order_num").css("display", "block");
                                     $("#down_order_time").css("display", "block");
                                     $("#receiver_tel").css("display", "block");
                                     $("#goods_type").css("display", "block");
                                     $("#desc").css("display", "block");
                                     $("#moreunfold").css("display", "block");
                                     $('.main li:gt(3)').css('display', 'none');
                                     peiSongStatus = "闪电侠正在前往收货地点";
                                     peiSongStatus2 = "等待收货";
                                     // YouHuiMoney CodeNum
                                     peiSongStatusTime = data.data.NaDaodate;
                                     addStatus();
                                     $(".assess_button").css("display", "block");
                                     status4 = false;
                                 }
                                 break;
                             case 6:
                                 if (status6 == true) {
                                     $(".order_state").html("已完成");
                                     peiSongStatus = "已送达";
                                     peiSongStatus2 = "等待收货";
                                     peiSongStatusTime = data.data.SongDaDate;
                                     addStatus();
                                     var nodeNumStr = "<p id='code_num'>验证码:<span>" + data.data.CodeNum + "</span></p>";
                                     $(".status_li .right").eq(4).append(nodeNumStr);
                                     status6 = false;
                                 }
                                 break;
                             case 7:
                                 if (status7 == true) {
                                     peiSongStatus = "已收货";
                                     peiSongStatus2 = "跑男完成订单";
                                     peiSongStatusTime = data.data.SongDaDate;
                                     addStatus();
                                     status7 = false;
                                 }
                                 break;
                             case 10:
                                 return false
                                 break;
                         }
                     }
                 } else {
                     $.alert(data.msg);
                     return false;
                 }

             },
             error: function() {
                 $.alert("无法获得订单详情");
                 return false
             }
         });
     }
 } else if (sdType == "5") {
     var orderDetail = function ajaxOrderDetail() {
         $.ajax({
             type: "get",
             url: currentUrl + "/interfaceDOC/firstProject/User.ashx?action=Get_DetailBangPai",
             data: {
                 "OrderId": OrderId
             },
             dataType: "json",
             success: function(data) {
                 // console.log(data)
                 //console.log(data.data.Phone);
                 if (data.msgcode == "1") {
                     // 初始化Dom
                     IsPingJia = data.data.IsPingJia;
                     if (IsPingJia == "0") {
                         $(".assess_button").html("评价");
                     } else {
                         $(".assess_button").html("再来一单");
                     }
                     $(".time_output").html("等待中" + data.data.DownOrderTime);
                     $("#order_num span").html(data.data.OrderHao);
                     $("#down_order_time span").html(data.data.DownOrderTime);
                     $("#buy_add span").html(data.data.BangXinxi);
                     $("#receiver_add span").html(data.data.QIAddress);
                     $("#receiver_tel span").html(data.data.ZhongTel);
                     $("#goods_type span").html(data.data.BangShiChang);
                     var totalMoney = data.data.ServerMoney - data.data.YouHuiMoney;
                     (totalMoney < 0 ? "0" : totalMoney);
                     $("#order_money span").html("￥" + totalMoney + "(服务费￥" + data.data.ServerMoney + ",已优惠￥" + data.data.YouHuiMoney + ")");
                     $("#order_distance span").html(data.data.OrderLiCheng + "km");
                     $("#desc span").html(data.data.Desc);
                     $("#peisong_name").html(data.data.Name);
                     $("#peisong_tel").html(data.data.Phone);
                     //闪电排队dom改变
                     if (sdType == "5") {
                         $("#buy_add .name").html("排队信息");
                         $("#receiver_add .name").html("排队地点");
                     }
                     $("#courier_header").css("background-image", "url(" + data.data.Image + ")");
                     //刷新页面;
                     orderStatus = data.data.Status;
                     // 取消订单，返回首页；
                     if (orderStatus == 8) {
                         window.location.href = "../index.html";
                     }
                     (orderStatus == 10 ? orderStatus = 3 : orderStatus);

                     for (var i = 0; i <= orderStatus; i++) {
                         switch (i) {
                             case 1:
                                 if (status1 == true) {
                                     $(".order_state").html("等待排队");
                                     peiSongStatus = "闪电侠接单成功";
                                     peiSongStatus2 = "等待闪电侠排队";
                                     peiSongStatusTime = data.data.QingDate;
                                     addStatus();
                                     status1 = false;
                                 }
                                 break;
                             case 2:
                                 if (status2 == true) {
                                     peiSongStatus = "跑男正在路上,请耐心等待";
                                     peiSongStatus2 = "等待闪电侠完成订单";
                                     peiSongStatusTime = data.data.QuChuFaDate;
                                     addStatus();
                                     status2 = false;
                                 }
                                 break;
                             case 3:
                                 if (status3 == true) {
                                     peiSongStatus = "闪电侠到达目的地,请耐心等待";
                                     peiSongStatus2 = "等待闪电侠完成订单";
                                     peiSongStatusTime = data.data.DaoDaDate;
                                     addStatus();
                                      //排队倒计时 2017.7.18 GJC
                                      //计算从开始排队到现在的逝去时间
                                      //difDate 逝去的时间
                                      //倒计时的时间
                                     var startStr = data.data.DaoDaDate.replace(/-/g,"/");
                                     var startDate = new Date(startStr);//将字符串转化为时间 
                                     var nowDate = new Date();
                                     var difDate=nowDate-startDate;
                                     // var difDate=29.9*60*1000;
                                     var paiTime=Number(data.data.BangShiChang)*60*1000;
                                     var cutDownTime=(paiTime-difDate)>0?paiTime-difDate:0;
                                    cutDownTime=parseInt(cutDownTime)/1000;
                                    // 如果还在排队中
                                    //ctd=cutDownTime
                                    if(cutDownTime>0){
                                        var ctdStr="<p id='ctd_time'>正在排队中<span></span></p>";
                                         $(".status_li .right").eq(2).append(ctdStr);
                                        //毫秒转换时分秒，并进行倒计时
                                        function formatTime(time){
                                            setInterval(function(){
                                                var hours=0,
                                                minutes=0,
                                                seconds=0;
                                                if(time>0){
                                                    var hours=Math.floor(time / (60 * 60))
                                                    var minutes=Math.floor(time / 60) - (hours * 60); 
                                                    var seconds=Math.floor(time) - (hours * 60 * 60) - (minutes * 60); 
                                                    if(hours<10){
                                                        hours="0"+hours;
                                                    };
                                                    if(minutes<10){
                                                        minutes="0"+minutes;
                                                    };
                                                    if(seconds<10){
                                                        seconds="0"+seconds;
                                                    };
                                                    $("#ctd_time span").html(hours+":"+minutes+":"+seconds);
                                                    time--;
                                                }else{
                                                    $("#ctd_time").remove();
                                                }
                                            },1000)  
                                        }
                                        formatTime(cutDownTime);
                                    }else{
                                        $("#ctd_time").remove();
                                    }
                                    //插入验证码
                                    var nodeNumStr = "<p id='code_num'>验证码:<span>" + data.data.CodeNum + "</span></p>";
                                     $(".status_li .right").eq(2).append(nodeNumStr);
                                     status3 = false;
                                 }
                                 break;
                             case 7:
                                 //完成排队
                                 if (status7 == true) {
                                     $(".order_state").html("已完成");
                                     $(".time_output").css("display", "none");
                                     $(".time_output").html(data.data.DownOrderTime);
                                     $("#order_num").css("display", "block");
                                     $("#down_order_time").css("display", "block");
                                     $("#receiver_tel").css("display", "block");
                                     $("#goods_type").css("display", "block");
                                     $("#desc").css("display", "block");
                                     $("#moreunfold").css("display", "block");
                                     $('.main li:gt(3)').css('display', 'none');
                                     peiSongStatus = "已完成";
                                     peiSongStatus2 = "已完成排队服务,感谢您的使用";
                                     // YouHuiMoney CodeNum
                                     peiSongStatusTime = data.data.ShouHuoDate;
                                     $("#ctd_time").remove();
                                     addStatus();
                                     $(".assess_button").css("display", "block");
                                     status7 = false;
                                 }
                                 break;
                         }
                     }
                 } else {
                     $.alert(data.msg);
                     return false;
                 }

             },
             error: function() {
                 $.alert("无法获得订单详情");
                 return false
             }
         });
     }
 }

 orderDetail;
 // 动态请求
 var b = setTimeout(orderDetail, 0);
 var t = setInterval(orderDetail, 10000)
     //拨打配送人员电话
 $("#call_peisong").click(function() {
     var callStr = "tel:" + $("#peisong_tel").html();
     console.log(callStr);
     window.location.href = callStr;
 })
 $("#pei_add").click(function() {
     alert("暂不支持此功能")
 })

 function addStatus() {
     var addstr = "";
     addstr += "<div class='status_row flex_row'>";
     addstr += "<i class='iconfont icon-dian-copy'></i>";
     addstr += "<div class='status_li flex_row flex_between'>"
     addstr += "<div class='left'>";
     addstr += "<p>" + peiSongStatus + "</p>";
     addstr += "<p>" + peiSongStatus2 + "</p>";
     addstr += "</div>";
     addstr += "<div class='right'><p>" + peiSongStatusTime + "</p></div>";
     addstr += "</div></div>";
     $("#peisong_status").append(addstr);
 }
 $(".assess_button").click(function() {
         if (IsPingJia == "0") {
             window.location.href = "../html/assess.html";
         } else {
             window.location.href = "../index.html";
         }
     })
     //获取用户信息
 var userInfo = localStorage.getItem("userInfo");
 var userInfoObj = JSON.parse(userInfo);
 $(".cancel_button").click(function() {
         $.confirm({
             title: '确定取消？',
             text: '取消订单根据情况会扣除一定费用',
             onOK: function() {
                 //点击确认
                 $.ajax({
                     type: "post",
                     url: currentUrl + "/api/order/cancel",
                     data: {
                         "id": OrderId,
                         "UserId": userInfoObj.data.UserId,
                         "UserTel": userInfoObj.data.Phone
                     },
                     success: function(data) {
                         console.log(data);
                         if (data.isOk == true) {
                             if (data.data.lossMoney != "0") {
                                 lossStr = "已扣除" + data.data.lossMoney + "元白跑费";
                                 $.alert(data.msg + lossStr);
                             } else if (data.data.lossMoney == "0") {
                                 $.alert(data.msg);
                             }
                         } else if (data.isOk == false) {
                             $.alert("该订单已无法取消，请联系客服")
                         }
                     }
                 })
             },
             onCancel: function() {
                 return false
             }
         });

     })
     //返回到我的订单页	
 $(".order_status #go_back").click(function() {
     window.location.href = "../html/my_order.html";
 })


